package handler;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

import bean.Test;
import service.TestService;

public class QueryEntities implements Controller {
    private TestService service;

    public void setService(TestService service) {
        this.service = service;
    }

    public ModelAndView handleRequest(HttpServletRequest req, HttpServletResponse resp) {
        ModelAndView modelAndView = new ModelAndView();
        String keywords = null;
        String methodValue = req.getMethod();
        if (methodValue.equals("POST")) {
            keywords = req.getParameter("kw");
        }
        List<Test> entities = service.query(keywords);
        modelAndView.addObject("entities", entities);
        modelAndView.setViewName("index");
        return modelAndView;
    }
}
